package com.bysj.sausys.controller.portal;

import com.bysj.sausys.beans.PageQuery;
import com.bysj.sausys.beans.PageResult;
import com.bysj.sausys.common.DataDowConst;
import com.bysj.sausys.common.JsonData;
import com.bysj.sausys.service.ISysDataDowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * 资源下载Controller
 *
 * @author WangZK
 */
@Api(description = "资源下载接口")
@Controller
@RequestMapping("/datadow")
public class DataDowController {

    @Resource
    private ISysDataDowService sysDataDowService;

    /**
     * 分页获取列表
     *
     * @param pageNo   页码
     * @param pageSize 每页显示条数
     * @return
     */
    @ApiOperation(value = "分页获取资源下载列表接口")
    @RequestMapping(value = "/getPageIsEnable", method = RequestMethod.GET)
    @ResponseBody
    public JsonData getPageIsEnable(@ApiParam(value = "页码") @RequestParam(required = false, defaultValue = "1") int pageNo,
                                    @ApiParam(value = "每页显示条数") @RequestParam(required = false, defaultValue = "10") int pageSize,
                                    HttpServletRequest request) {
        String path = request.getSession().getServletContext()
                .getRealPath("/");
        PageResult result = sysDataDowService.getPageByStatus(path, DataDowConst.ENABLE.getCode(), new PageQuery(pageNo, pageSize));
        return JsonData.success(result);
    }

}
